Spotlight PRO
Spotlight lets scripts add their own resources to the system Spotlight index. When the user taps one of those results, Scripting runs the same script's spotlight.tsx file.
Spotlight indexing requires Scripting PRO.
Index Items
id is local to the current script. Calling Spotlight.index again with the same id updates the existing item.
Item Fields
Only id and title are required. Apart from the two Scripting-only fields below, every field maps 1:1 to a property of Apple's CSSearchableItemAttributeSet and is grouped here the same way Apple documents them.
Scripting-only
id(required) — Script-local identifier, unique within the current script. Returned asSpotlight.current.idwhen the result is tapped.parameters— Arbitrary JSON delivered tospotlight.tsxasSpotlight.current.parameters. This is not a Spotlight metadata field; it is how you pass context to your tap handler.
General
title(required) — Primary title shown in the result.displayName— Display name; falls back totitlewhen omitted.alternateNames— Other names the item can also be found by.contentType— Uniform Type Identifier (UTType) used to pick the result icon, e.g."public.image","com.adobe.pdf","public.movie","public.folder". Defaults to plain text.contentURL— URL of the underlying content; use afile://URL for local content.thumbnailData— Thumbnail image bytes. Takes priority overthumbnailURL.thumbnailURL— Local file URL string pointing to a thumbnail image.keywords— Extra terms the item should match against.rankingHint— Higher numbers rank the item higher among results.supportsNavigation— Marks the item as navigable; pair withlatitude/longitude.supportsPhoneCall— Marks the item as callable; pair withphoneNumbers.
Documents
contentDescription— Longer description shown under the title.subject— Subject of the content.kind— Human-readable kind, e.g."Note","Invoice".creator— Entity that created the content.pageCount— Number of pages.fileSize— Content size in bytes.
Messaging
textContent— Full searchable body text; improves recall for free-text queries.authorNames— Author display names.emailAddresses— Associated email addresses.phoneNumbers— Associated phone numbers.
Media
comment— Free-form comment.contentCreationDate— Creation date. Defaults to the first index time when omitted.contentModificationDate— Modification date. Defaults to the last index time when omitted.lastUsedDate— When the item was last used.
Events
startDate/endDate— For event-like items.dueDate/completionDate— For task-like items.allDay— Whether the event spans the whole day.
Places
latitude/longitude/altitude— Coordinates, in degrees / degrees / meters.namedLocation— Human-readable place name.city/stateOrProvince/country/postalCode/fullyFormattedAddress— Address components.
Item-level
expirationDate— When Spotlight should drop the item from the index. Omit it to keep the item indexed until you delete it explicitly.
Notes:
- Dates (
contentCreationDate,lastUsedDate,startDate,expirationDate, ...) accept aDate, an ISO-8601 string, or a numeric timestamp in seconds. - Thumbnails:
thumbnailDatawins overthumbnailURLwhen both are set.
A full example touching every group:
Search Reliability
How well an item surfaces is decided by the system, not by Scripting. A few things help:
- Put every searchable term in
keywordsas a separate entry. Spotlight matches whole words and word prefixes, not arbitrary substrings — searching"part"will match"partner"but searching"art"will not match it. For dictionary-style data, add each spelling, inflection, and alternate form as its own keyword (e.g.["run", "runs", "running", "ran"]). - Keep
titleshort and exact. It is the strongest matching field; put the canonical term there and push variants intokeywords/alternateNames. - Use
rankingHint(higher = earlier) to bias ranking among your own items. textContentimproves recall for longer free-text queries (definitions, body text).
Limitations to be aware of:
- Spotlight does not do substring/fuzzy matching, so mid-word or partial queries may not match. Add explicit prefixes as keywords if you need them.
- Apple's built-in results (Dictionary, Contacts, etc.) are privileged system data sources and are ranked separately. Custom items generally cannot outrank them for short, common words, no matter how they are tagged.
Large Indexes
indexItems accepts large arrays and submits them to the system in batches; you can index several thousand items per script. await the call — it resolves once the work is handed to Spotlight, and awaiting is the recommended way to know indexing finished and to catch errors. Updating an existing id overwrites the previous item, so re-indexing is safe to call repeatedly.
Handle Taps
Create a spotlight.tsx file in the script project:
Spotlight.current is null in other script environments. It is available when spotlight.tsx is launched from a Spotlight result.
Spotlight tap parameters are not exposed through Script.queryParameters.
Manage Items
Users can also manage indexed items from Tools > Spotlight, including deleting entries whose script or spotlight.tsx file no longer exists.
